package it.uai.domainsMigrator;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

import org.apache.log4j.Logger;

public class DomainsManager {

	private static final Logger logger = Logger.getLogger(DomainsManager.class);

	private ArrayList<Domain> domini = new ArrayList<Domain>();

	public DomainsManager(String inputFileNameList, String basePath) {

		BufferedReader br = null;

		try {

			String sCurrentLine;

			br = new BufferedReader(new FileReader(inputFileNameList));

			while ((sCurrentLine = br.readLine()) != null) {
				if (!sCurrentLine.startsWith("#")) {
					Domain dominio = new Domain(sCurrentLine, basePath);
					domini.add(dominio);
					logger.debug("Aggiunto un nuovo dominio: "
							+ dominio.getNome());
				}
			}

		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if (br != null)
					br.close();
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}

	}

	public Domain getNextDomain() {

		for (Domain dominio : domini) {

			if (!dominio.isProcessed()) {

				return dominio;

			}

		}
		return null;

	}

}
